package com.ruoyi.project.module.paytype.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.paytype.domain.Paytype;
import com.ruoyi.project.module.paytype.service.IPaytypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 支付方式 信息操作处理
 * 
 * @author frey
 * @date 2018-11-13
 */
@Controller
@RequestMapping("/module/paytype")
public class PaytypeController extends BaseController
{
    private String prefix = "module/paytype";
	
	@Autowired
	private IPaytypeService paytypeService;
	
	@RequiresPermissions("module:paytype:view")
	@GetMapping()
	public String paytype()
	{
	    return prefix + "/paytype";
	}
	
	/**
	 * 查询支付方式列表
	 */
	@RequiresPermissions("module:paytype:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Paytype paytype)
	{
		startPage();
        List<Paytype> list = paytypeService.selectPaytypeList(paytype);
		return getDataTable(list);
	}
	
	/**
	 * 新增支付方式
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存支付方式
	 */
	@RequiresPermissions("module:paytype:add")
	@Log(title = "支付方式", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Paytype paytype)
	{		
		return toAjax(paytypeService.insertPaytype(paytype));
	}

	/**
	 * 修改支付方式
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Paytype paytype = paytypeService.selectPaytypeById(id);
		mmap.put("paytype", paytype);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存支付方式
	 */
	@RequiresPermissions("module:paytype:edit")
	@Log(title = "支付方式", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Paytype paytype)
	{		
		return toAjax(paytypeService.updatePaytype(paytype));
	}
	
	/**
	 * 删除支付方式
	 */
	@RequiresPermissions("module:paytype:remove")
	@Log(title = "支付方式", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(paytypeService.deletePaytypeByIds(ids));
	}
	
}
